package cn.fbs.passcontroller;

import cn.fbs.param.AssignParam;
import cn.fbs.service.AuthorityService;
import cn.fbs.service.UserInfoService;
import cn.fbs.vo.SysGroupVo;
import cn.fbs.vo.SysUserVo;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.hyperic.sigar.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.text.DecimalFormat;
import java.util.ArrayList;

/**
 * @author yuyuesheng
 * @version 1.0
 * @description: TODO
 * @date 2021/4/1 10:30
 */
@Api(tags = "用户模块")
@RestController
@RequestMapping()
public class UserController {


    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private AuthorityService authorityService;

    @ApiOperation("登录,登录成功返回sessionId,将sessionId放到请求头中")
    @GetMapping("user/login")
    public String login(String loginName,String password){
        return authorityService.login(loginName,password);
    }

    @PostMapping("users/regist")
    @ApiOperation("注册")
    public Object regist(@RequestBody @Valid SysUserVo vo) {
        return userInfoService.regist(vo);
    }


    @PostMapping("users/assignTarget")
    @ApiOperation("人为指定某专家审核某个舰船级别下的某个目标,则其他专家对改目标的审核意见皆为通过")
    public String assignTarget(@RequestBody AssignParam assignParam) {
        return userInfoService.assignTarget(assignParam.getExpertId(),assignParam.getTargetIds());
    }

    @GetMapping("users/getAllGroup")
    @ApiOperation("所有用户组")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize", value = "每页条数"),
            @ApiImplicitParam(name = "pageNo", value = "多少页")}
    )
    public Object getAllGroup(Integer pageSize,Integer pageNo){
        return userInfoService.getAllGroup(pageSize,pageNo);
    }

    @PostMapping("users/addGroup")
    @ApiOperation("新增小组")
    public String addGroup(@RequestBody SysGroupVo vo) {
        return userInfoService.addGroup(vo);
    }



    @ApiOperation("删除小组")
    @GetMapping("users/deleteGroup")
    public Object deleteGroup(Long groupId){
        return userInfoService.deleteGroup(groupId);
    }



    @GetMapping("users/deleteUser")
    @ApiOperation("删除用户")
    public Object deleteUser(Long UserId){
        return userInfoService.deleteUser(UserId);
    }


    @GetMapping("users/getUsers")
    @ApiOperation("查询用户列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "searchName", value = "登录或者用户名"),
            @ApiImplicitParam(name = "groupId", value = "小组主键"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数"),
            @ApiImplicitParam(name = "pageNo", value = "多少页")}
    )
    public Object getUsers(String searchName , Long groupId,
                                  Integer pageSize,Integer pageNo){
        return userInfoService.getUsers(searchName,groupId,pageSize,pageNo);
    }








}
